<template>
  <div class="login">
    <div class="login_box">
      <div class="icon_box">
        <img src="../assets/logo.png" alt />
      </div>
      <!-- 登录区域 -->
      <el-form ref="loginFormRef" class="login_form" label-width="0px;" :model="loginForm" :rules="loginFromRoules">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-s-custom"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" type="password" prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login" >登录</el-button>
        </el-form-item>
      </el-form>
      <el-row class="copyright">
        <p>Copy right ©  rufeike 2019. All rights reserved</p>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        username: "",
        password: ""
      },
      loginFromRoules: {
        // 验证码用户名是否合法
        username: [
          { required: true, message: "请输入登录名称", trigger: "blur" },
          { min: 2, max: 15, message: "长度在 2 到 15 个字符", trigger: "blur" }
        ],
        // 验证密码是否合法
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 15, message: "长度在 6 到 15 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    // 表单数据提交
    login () {
      // 表单提交数据前验证 valid为验证结果，验证通过为true
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return;
        let result = await this.$http.post("/api/auth/login", this.loginForm);
        console.log(result);
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.login {
  background-color: #2b4b6c;
  height: 100vh;
}

.login_box {
  width: 320px;
  height: 260px;
  // background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .icon_box {
    // width: 80px;
    height: 60px;
    // border-radius: 50%;
    // padding: 10px;
    // box-shadow: 0 0 10px #ddd;
    box-sizing: border-box;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    // background-color: #fff;

    img {
      width: 100%;
      height: 100%;
      // border-radius: 50%;
    }
  }
}

button {
  padding: 0px 20px;
  width:100%;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.copyright{
  position: absolute;
  bottom:-65px;
  width:100%;
  color:#fff;
  text-align: center;
}

</style>
